<table width="100%"  border="0" cellspacing="1" cellpadding="5">
  <tr align="left">
    <td colspan="4" align="center" bgcolor="#999999" ><strong>CẬP NHẬT HỖ TRỢ ONLINE</strong></td>
    </tr>
      <td colspan="4" align="left" valign="top">{$msg}</td>
    </tr>
  <tr>
    <td colspan="4" align="left" valign="top">
    	<table width="100%" cellpadding="5" cellspacing="1" bgcolor="#0099FF" id="o_group">
            <tr>
                <th width="11%" align="left" bgcolor="#CCCCCC">Tên nhóm</th>
                <th align="left" bgcolor="#CCCCCC">Người hỗ trợ</th>
                <th align="center" bgcolor="#CCCCCC">Xóa</th>
            </tr>
            {foreach from=$OnlineSupport item=ogroup key=gid}
             <tr id="sg_{$gid}" lang="{$gid}" class="os_group">
                <td width="11%" align="left" bgcolor="#FFFFFF" valign="top">
                	<input name="og_name[{$gid}]" value="{$ogroup.name}" size="30" type="text"/>
                </td>
                <td align="left" bgcolor="#FFFFFF">
                	<table width="100%" cellpadding="5" cellspacing="1" bgcolor="#0099FF" id="o_user_{$gid}">
                        <tr>
                            <th width="11%" align="left" bgcolor="#CCCCCC">Tên</th>
                            <th align="left" bgcolor="#CCCCCC">Yahoo</th>
                            <th align="left" bgcolor="#CCCCCC">Skype</th>
                            <th align="center" bgcolor="#CCCCCC" nowrap="nowrap">Xóa</th>
                        </tr>
                        {foreach from=$ogroup.users item=user key=uid}
                        <tr id="su_{$gid}_{$uid}" lang="{$uid}" class="os_user_{$gid}">
                            <td width="11%" align="left" bgcolor="#FFFFFF">
                            	<input name="u_name[{$gid}][{$uid}]" value="{$user.name}" size="30" type="text"/>
                            </td>
                            <td align="left" bgcolor="#FFFFFF">
                            	<input name="u_yahoo[{$gid}][{$uid}]" value="{$user.yahoo}" size="30" type="text"/>
                            </td>
                            <td align="left" bgcolor="#FFFFFF">
                            	<input name="u_skype[{$gid}][{$uid}]" value="{$user.skype}" size="30" type="text"/>
                            </td>
                            <td align="center" bgcolor="#FFFFFF" onclick="fn_remove_support_user('{$gid}_{$uid}');" class="cp">[ Xóa ]</td>
                        </tr>
                       {/foreach} 
                	</table>
                    <input type="button" value="Thêm người hỗ trợ" class="mt15" onclick="fn_add_support_user({$gid});"/>
                </td>
                 <td width="11%" align="center" bgcolor="#FFFFFF" nowrap="nowrap" onclick="fn_remove_support_group({$gid});" class="cp">
                	[ Xóa ]
                </td>
             </tr>
            {/foreach}
      </table>
      <input type="button" value="Thêm nhóm hỗ trợ" class="mt15 mb15" onclick="fn_add_support_group();"/>
      <hr />
    </td>
  </tr>
   <tr>
    <td width="29%" align="right" valign="middle"><input type="submit" name="Submit" value="Cập nhật" ></td>
    <td width="14%" align="center" valign="middle"><input type="reset" name="Submit2" value="Nhập lại"  /></td>
    <td width="57%" colspan="2">
      	<input type="button" value="Đóng cửa sổ"  onclick="window.close();">    
    </td>
  </tr>
</table>
{literal}
<script>
function fn_add_support_user(gid)
{
	var new_uid = 0;
	
	jQuery('.os_user_' + gid).each(function(){
		if(new_uid <= parseInt(this.lang))
		{
			new_uid = parseInt(this.lang) + 1;
		}
	});
	
	jQuery('#o_user_' + gid).append('<tr id="su_'+new_uid+'" lang="'+new_uid+'" class="os_user_'+gid+'">\
									<td width="11%" align="left" bgcolor="#FFFFFF">\
										<input name="u_name['+gid+']['+new_uid+']" value="" size="30" type="text"/>\
									</td>\
									<td align="left" bgcolor="#FFFFFF">\
										<input name="u_yahoo['+gid+']['+new_uid+']" value="" size="30" type="text"/>\
									</td>\
									<td align="left" bgcolor="#FFFFFF">\
										<input name="u_skype['+gid+']['+new_uid+']" value="" size="30" type="text"/>\
									</td>\
									<td align="center" bgcolor="#FFFFFF" onclick="fn_remove_support_user('+new_uid+');" class="cp">[ Xóa ]</td>\
								</tr>');
	
}

function fn_add_support_group()
{
	var html 	=  '';
	var new_gid = 0;
	
	jQuery('.os_group').each(function(){
		if(new_gid <= parseInt(this.lang))
		{
			new_gid = parseInt(this.lang) + 1;
		}
	});
	
	jQuery('#o_group').append('<tr id="sg_'+new_gid+'" lang="'+new_gid+'" class="os_group">\
										<td width="11%" align="left" bgcolor="#FFFFFF" valign="top">\
											<input name="og_name['+new_gid+']" value="" size="30" type="text"/>\
										</td>\
										<td align="left" bgcolor="#FFFFFF">\
											<table width="100%" cellpadding="5" cellspacing="1" bgcolor="#0099FF" id="o_user_'+new_gid+'">\
												<tr>\
													<th width="11%" align="left" bgcolor="#CCCCCC">Tên</th>\
													<th align="left" bgcolor="#CCCCCC">Yahoo</th>\
													<th align="left" bgcolor="#CCCCCC">Skype</th>\
													<th align="center" bgcolor="#CCCCCC" nowrap="nowrap">Xóa</th>\
												</tr>\
												<tr id="su_'+new_gid+'_0" lang="0" class="os_user_'+new_gid+'">\
													<td width="11%" align="left" bgcolor="#FFFFFF">\
														<input name="u_name['+new_gid+'][0]" value="" size="30" type="text"/>\
													</td>\
													<td align="left" bgcolor="#FFFFFF">\
														<input name="u_yahoo['+new_gid+'][0]" value="" size="30" type="text"/>\
													</td>\
													<td align="left" bgcolor="#FFFFFF">\
														<input name="u_skype['+new_gid+'][0]" value="" size="30" type="text"/>\
													</td>\
													<td align="center" bgcolor="#FFFFFF" onclick="fn_remove_support_user(\''+new_gid+'_0\');" class="cp">[ Xóa ]</td>\
												</tr>\
											</table>\
											<input type="button" value="Thêm người hỗ trợ" class="mt15" onclick="fn_add_support_user('+new_gid+');"/>\
										</td>\
										 <td width="11%" align="center" bgcolor="#FFFFFF" nowrap="nowrap" onclick="fn_remove_support_group('+new_gid+');" class="cp">\
											[ Xóa ]\
										</td>\
									 </tr>');
}

function fn_remove_support_user(uid)
{
	if(confirm("Bạn có chắc chắc muốn xóa người hỗ trợ này không?"))
	{
		jQuery("#su_" + uid).remove();
	}
}

function fn_remove_support_group(gid)
{
	if(confirm("Bạn có chắc chắc muốn xóa nhóm hỗ trợ này không?"))
	{
		jQuery("#sg_" + gid).remove();
	}
}

</script>
{/literal}